﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Web.UI;

namespace LabMS.Common
{
    public class JShelper
    {
        /// <summary>
        /// 注册js的alert
        /// </summary>
        /// <param name="page"></param>
        /// <param name="hander"></param>
        /// <param name="content"></param>
        static public void JSAlert(Page page,string hander, string content)
        {
            page.ClientScript.RegisterClientScriptBlock(page.GetType(),hander, "<script>alert(\"" + content + "\")</script>");
        }

        static public void JsAlertAndClose(Page page, string Header, string Content) 
        {
            page.ClientScript.RegisterClientScriptBlock(page.GetType(),Header, "<script>alert(\"" + Content + "\");window.opener=null;window.close()</script>");
        }
        
        /// <summary>
        /// 注册js的页面跳转
        /// </summary>
        /// <param name="page"></param>
        /// <param name="hander"></param>
        /// <param name="content"></param>
        static public void JSRedirect(Page page, string hander, string URL)
        {
            page.ClientScript.RegisterClientScriptBlock(page.GetType(), hander, "<script>window.location.href='" + URL + "'</script>");
        }

        /// <summary>
        /// 注册js的alert,后并跳转
        /// </summary>
        /// <param name="page"></param>
        /// <param name="hander"></param>
        /// <param name="content"></param>
        static public void JSAlertAndRedirect(Page page, string hander, string content, string URL)
        {
            page.ClientScript.RegisterClientScriptBlock(page.GetType(),hander, "<script>alert(\"" + content + "\");window.location.href='" + URL + "';</script>");
        }

        /// <summary>
        /// 注册js刷新 关闭
        /// </summary>
        /// <param name="page"></param>
        /// <param name="hander"></param>
        /// <param name="content"></param>
        static public void JSAlertAndRefreshAndClose(Page page, string hander, string content)
        {
            page.ClientScript.RegisterClientScriptBlock(page.GetType(), hander, "<script>alert(\"" + content + "\");window.opener.location.href = window.opener.location.href;this.window.close();</script>");
        }
    }
}
